package com.company.demo.handlers;

import com.company.demo.bean.NewsUser;
import com.company.demo.bean.Student;
import com.company.demo.service.ISomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller//返回页面资源
@RequestMapping("/test")
public class SomeHandler {

    @Autowired
    private ISomeService service;

    @RequestMapping("/userregister")
    public String registerUserHandle(NewsUser newsUser, Model model){

        model.addAttribute("uname",newsUser.getUname() );
        model.addAttribute("upwd",newsUser.getUpwd());
        
        service.addUser(newsUser);

        //查询信息
        List<NewsUser> list =service.selectUser();
        model.addAttribute("newsUser",list);

        return "jsp/welcome";
    }



    @RequestMapping("/studentregister")
    public String registerStudentHandle(Student student, Model model){

        model.addAttribute("name",student.getName());
        model.addAttribute("age",student.getAge());

        service.addStudent(student);

        //查询信息
        List<Student> list =service.selectStudent();
        model.addAttribute("student",list);

        return "jsp/welcome";
    }

}
